package org.garbagecan.quartzstudy.stateful;

import org.garbagecan.quartzstudy.TestUtil;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;

public class Test {
	public static void main(String[] args) throws Exception {
		// Please pay attention to org.quartz.jobStore.misfireThreshold=1 
		// in my quartz.properties
		Scheduler scheduler = TestUtil.getScheduler();
		
		JobDetail jobDetail = JobBuilder.newJob(MyStatefulJob.class)
				.withIdentity("myjob","mygroup")
				.usingJobData("mykey1", "myvalue1")
				.usingJobData("mykey2", "myvalue2")
				.build();
		
		Trigger trigger = TriggerBuilder.newTrigger()
				.withIdentity("mytrigger", "mygroup")
				.forJob(jobDetail)
				.startNow()
				.withPriority(5)
				.withSchedule(SimpleScheduleBuilder
					.simpleSchedule()
					.withIntervalInSeconds(5)
					.repeatForever())
				.build();
		
		scheduler.scheduleJob(jobDetail, trigger);
		scheduler.start();
		Thread.sleep(10 * 60 * 000);
	}
}
